import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { viteMockServe } from "vite-plugin-mock";
import cesium from "vite-plugin-cesium";

export default defineConfig({
	define: {
		CESIUM_BASE_URL: JSON.stringify("/cesium"),
	},
	resolve: {
		alias: {
			"@": resolve(__dirname, "src"),
		},
	},
	assetsInclude: ["**/*.glb"],
	plugins: [
		vue(),
		AutoImport({
			resolvers: [ElementPlusResolver()],
			imports: ["vue", "vue-router", "pinia"],
			dts: "src/types/auto-imports.d.ts",
			eslintrc: {
				enabled: true,
			},
		}),
		Components({
			resolvers: [ElementPlusResolver()],
			dts: "src/types/components.d.ts",
		}),
		cesium(),
		viteMockServe({
			mockPath: "mock",
			// injectCode: `
			// 	import { setupProdMockServer } from './mock/index';
			// 	setupProdMockServer();
			//   `,
			logger: true,
		}),
	],
	css: {
		preprocessorOptions: {
			scss: {
				additionalData: '@use "@/styles/variables.scss" as *;',
			},
		},
	},
	server: {
		port: 5173,
		open: true,
		cors: true,
		proxy: {
			"/api": {
				target: "http://localhost:3000",
				changeOrigin: true,
				rewrite: path => path.replace(/^\/api/, ""),
			},
		},
	},
});
